#include<stdio.h>
#include<string.h>
#include<math.h>
#define N 100
int zhuanhuan(char s[N])
{
	int len=strlen(s);
	int i;
	int sum=0;
	int n=0;
	for(i=len-1; i>=0; i--)
	{
		if(s[i]-'0'<=10)
		{
			sum=sum+(s[i]-'0')*pow(16,n);
		}
		else
		{
			sum=sum+(s[i]+10-'A')*pow(16,n);
		}
		n++;
	}
	return sum;
}
int main ()
{
	char s[N];char str[N];
	while(gets(s)!=NULL)
	{
		int result;
		int i;int j=0;
		for(i=0;s[i]!='\0';i++)
		{
			if(s[i]>='\0'&&s[i]<='9'||s[i]>='A'&&s[i]<='F'||s[i]>='a'&&s[i]<='f')
			{
				str[j]=s[i];
				j++;
			}
		}
		result=zhuanhuan(str);
		printf("%d\n",result);
	}

	return 0;
}
